export default {
	data() {
		return {
			menuList: []
		};
	},
	methods: {
		/** 获取特定菜单列表的权限
		 * @param <Array> data
		 *
		 * [{
                name: '常规',
                list: [
                    {
                        id: 1,
                        name: '品种开台',
                        path: '/pages/production/openMachine/index',
                        state: 0,
                        icon: 'play-circle',
                        bgColor: 'rgb(21, 166, 87)',
                        count: 0,
                        pcRouterPath: ['smOpen', 'btOpen']
                    }
                ]
            }]
		 * */
		getMenuListPermission(data) {
			let cpData = JSON.parse(JSON.stringify(data));
			cpData.forEach(x => {
				x.list.forEach(k => {
					k.isShow = this.getMenuItemPermission(k);
				});
			});
			cpData.forEach(x => {
				x.list = x.list.filter(k => k.isShow);
			});
			cpData = cpData.filter(x => x.list.length);
			return cpData;
		},
		// 获取某个菜单项的权限
		getMenuItemPermission(item) {
			let userMenuList = getApp().globalData.userMenuList;
			let has = false;
			for (let i = 0; i < userMenuList.length; i++) {
				if (item.pcRouterPath.includes('any')) {
					has = true
				} else {
					has = item.pcRouterPath.includes(userMenuList[i].path);
				}
				if (has) {
					break;
				}
			}
			return has;
		}
	}
}
